// import {
//   getLoginInfo,
//   getInfo,
//   getToken
// } from '@/api/login.js'
export default {
  namespaced: true,
  state: () => ({
    userinfo: {

    },
    searchInfo: [],
    fabuinfo: []

  }),
  mutations: {
    setUserInfo: (state, payload) => {
      state.userinfo = payload
    },
    setFabuinfo: (state, payload) => {
      state.fabuinfo = payload
    },
    setSearchInfo: (state, payload) => {

      state.searchInfo = payload
    },
  },
  actions: {
    ACgetLoginInfo: ({
      commit,
      state
    }, payload) => {
      return new Promise(async (resolve, reject) => {
        getLoginInfo({
          username: payload.username + '@iccid',
          password: payload.password
        }).then(async (res) => {
          if (res.access_token) {
            state.token = res.access_token
            let ress = await getInfo()
            if (ress.code == 200) {
              state.user = ress.user
              getToken({
                username: ress.user.iccid
              }).then(resss => {
                if (resss.code == 200) {
                  state.realNameState = resss.data.data.real_status
                  state.chargeState = resss.data.data.charge_status
                }
              })
            }
            resolve(res.access_token)
          } else {
            reject(res.msg || 'error')
          }
        }).catch(err => {
          console.log(err);
        });

      })
    }
    // 	AcsetTokenInfo: ({
    // 		commit,
    // 		state
    // 	}, payload) => {
    // 		return new Promise(async (resolve, reject) => {
    // 			try {
    // 				let res = await clientLogin(payload);
    // 				console.log(res);
    // 				if (res.code == 200) {
    // 					commit('setTokenInfo', res.data.token)
    // 					resolve(res.data)
    // 				}
    // 			} catch (e) {
    // 				reject(e)
    // 			}
    // 		})
    // 	},

    // 	AcsetUserInfo: ({
    // 		commit,
    // 		state
    // 	}) => {
    // 		return new Promise(async (resolve, reject) => {
    // 			let res = await getUserInfo();
    // 			if (res.code == 200) {
    // 				uni.setStorageSync('user', res.data.user)
    // 				console.log('userinfo', res.data.user);
    // 				commit('setUserInfo', res.data.user)
    // 				resolve(res.data)
    // 			} else {
    // 				reject(res.msg)
    // 			}
    // 		})
    // 	},

  }
}
